package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:咭咭熊
 * Date:2021 - 08 - 06
 * Time:11:00
 */
public class Test6 {

    /***
     * 找到链表的中间节点——定义快慢指针：可对链表只进行 一次遍历
     * @param head
     * @return
     */
    public ListNode midListNode(ListNode head){
        ListNode fast = head;
        ListNode slow = head;
        while(fast != null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;
        }
        return slow;
    }
}
